package com.zhengze;

// 模糊匹配
public class Demo3 {
    public static void main(String[] args) {
        String re3 = "a.c";
        System.out.println("abc".matches(re3));  // true
        System.out.println("a&c".matches(re3));  // true
        System.out.println("a1c".matches(re3));  // true
        System.out.println("abbc".matches(re3));  // false

        /*
            注意：
            1. 单个数字匹配符是\d，不是%d
            2. 字符串中，\前面还必须加上转义符号\
                所以是\\d
         */
        System.out.println("----------");
        String re4 = "12\\d";
        System.out.println("123".matches(re4));  // true
        System.out.println("12a".matches(re4));  // false

        System.out.println("-----------------");
        String re5 = "java\\w";  // 注意：字符串里式\\
        System.out.println("javac".matches(re5));  // true
        System.out.println("java9".matches(re5));  // true
        System.out.println("java_".matches(re5));  // true
        System.out.println("java@".matches(re5));  // false
        System.out.println("java ".matches(re5));  // false

        System.out.println("------------------");
        String re6 = "a\\sc";
        System.out.println("a c".matches(re6));  // true
        System.out.println("a\tc".matches(re6));  // true

        System.out.println("------------------");
        String re7 = "a\\w{3}";
        System.out.println("aaaa".matches(re7));
        System.out.println("a".matches(re7));

        System.out.println("------------------");
        String re8 = "a{3}";
        System.out.println("aaa".matches(re8));
    }
}
